package cn.yotta.user.core.server.iface.login.impl;

import cn.yotta.user.api.params.login.BaseLoginRequest;
import cn.yotta.user.api.params.login.LoginByMobilePasswordRequest;
import cn.yotta.user.core.server.dto.user.UserDto;
import cn.yotta.user.core.server.exception.user.UserNotFindException;
import cn.yotta.user.core.server.iface.login.PasswordEncoder;
import cn.yotta.user.core.server.manager.captcha.CaptchaManager;
import cn.yotta.user.core.server.manager.user.UserManager;

/**
 * @author w_etw
 * @date 2023/4/15 20:50
 */
public class MobilePasswordLoginProvider extends AbstractPasswordLoginProvider<LoginByMobilePasswordRequest> {
    private final UserManager userManager;
    protected MobilePasswordLoginProvider(PasswordEncoder passwordEncoder,
                                          CaptchaManager captchaManager,
                                          Boolean skipCheck,
                                          UserManager userManager) {
        super(passwordEncoder, captchaManager, skipCheck);
        this.userManager = userManager;
    }

    @Override
    public Boolean support(BaseLoginRequest loginRequest) {
        return loginRequest.getClass().equals(LoginByMobilePasswordRequest.class);
    }


    @Override
    protected UserDto loadUser(String principal) throws UserNotFindException {
        return userManager.findUserByMobile(null,principal);
    }
}
